package com.guochu.utils;

import com.guochu.common.enums.ErrorEnum;

import java.util.Map;

/**
 * Element分页组件
 * @Author: luc
 * @Date: 2019-9-29 15:00
 */
public class Pagination {

    /**
     * 当前页
     */
    private Integer currentPage;

    /**
     * 单页数据行
     */
    private Integer pageSize;

    /**
     * 总记录数
     */
    private Integer total;

    public Pagination() {
    }

    public Pagination(Integer currentPage, Integer pageSize) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
    }

    public Integer getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(Integer currentPage) {
        this.currentPage = currentPage;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getTotal() {
        return total;
    }

    public void setTotal(Integer total) {
        this.total = total;
    }

    /**
     * 获取分页参数
     *
     * @param limit
     * @return
     * @throws Exception
     */
    public static Pagination getPagination(Map<String, Object> limit) throws Exception {

        Integer currentPage = MapUtils.getInteger(limit, "currentPage");
        Integer pageSize = MapUtils.getInteger(limit, "pageSize");

        if (null == currentPage || null == pageSize) {
            throw new Exception(ErrorEnum.A_DATA_ERROR.getMsg());
        }
        return new Pagination(currentPage, pageSize);
    }
}

